<template>
  <div>
    <a-card :bordered='false'>
      <f-search-form :more='false' @searchHandler='searchHandler'>
        <f-search-form-item label='部门名称' name='deptName' />
        <f-search-form-item label="状态" name="deptState" :showAll="false" type="select" :data="api.common.userStatus"></f-search-form-item>
      </f-search-form>
      <f-table ref='table' rowKey='deptId' :columns='columns' :multiple='false' :operator='operator' :params='queryParam' :api='api.dept' handler='hyDeptPageListHandler'>
         <span slot='deptState' slot-scope='text, record, index'>
          <a-switch v-model='record.deptState==1' checkedChildren='已启用' unCheckedChildren='已禁用' @change='(checked) => setDeptState(checked,record)' />
        </span>
        <span slot="deptType" slot-scope="text">
          <a-tag color="#2db7f5"  v-if='text=="ZS"'>招商</a-tag>
          <a-tag v-if='text=="ZY"'>自营</a-tag>
        </span>
        <span slot="proLevel" slot-scope="text">
          <a-tag color="#2db7f5"  v-if='text==1'>是</a-tag>
          <a-tag v-if='text==0'>否</a-tag>
        </span>
        <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='$refs.drawer.showDrawer(record)'>编辑</a>
            <a-divider type='vertical' />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item v-if="$auth('table.delete')">
                <a href='javascript:;' @click='$refs.table.del(record)'>删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <dept-drawer ref='drawer' @success='$refs.table.refresh()'></dept-drawer>
    </a-card>
  </div>
</template>
<script>
import deptDrawer from "./dept_drawer.vue"
import api from "./js/api"

export default {
  name: "TableList",
  components: {
    deptDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "添加",
      icon: "plus",
      that: this,
      handler: (table, that) => {
        this.$refs.drawer.showDrawer()
      }
    })
    operator.push({
      name: "同步数据",
      icon: "plus",
      that: this,
      handler: (table, that) => {
        this.http.confirm(this, {
          content: "确认同步部门数据吗?",
          url: api.dept.syncHyData,
          success: (me, data) => {
            this.$refs.table.refresh()
          }
        })
      }
    })
    operator.push({
      name: "删除",
      icon: "delete",
      batch: true,
      handler: function(table) {
        table.remove()
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        
      },
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "部门名称",
          align: "center",
          ellipsis: true,
          width:"150px",
          dataIndex: "deptName"
        },
        {
          title: "部门编码",
          align: "center",
          width:"100px",
          dataIndex: "deptCode"
        },
        {
          title: "负责人",
          align: "center",
          width:"100px",
          dataIndex: "saleManName"
        },
        {
          title: "业务类型",
          align: "center",
          width:"100px",
          dataIndex: "deptType",
          scopedSlots: { customRender: "deptType" },
        },
        {
          title: "省级",
          align: "center",
          width:"60px",
          sorter:true,
          dataIndex: "proLevel",
          scopedSlots: { customRender: "proLevel" },
        },
        {
          title: "开票税率",
          align: "center",
          width:"100px",
          dataIndex: "invoiceRate"
        },
        {
          title: "结算标准",
          align: "center",
          width:"100px",
          dataIndex: "settleRate"
        },
        {
          title: "状态",
          align: "center",
          scopedSlots: { customRender: "deptState" },
          width:"100px",
          dataIndex: "deptState"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width:"140px",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: { //设置状态
    setDeptState(check, record) {
      this.http.post(this, {
        url: this.api.dept.setDeptState,
        data: {
          ids: record.deptId,
          deptState: Number(check)
        },
        success(me, data) {
          record.deptState = data
        }
      })
    }
  }
}
</script>
